package com.xian.im.message.event;

import com.google.common.eventbus.Subscribe;
import com.xian.im.common.constant.EhcacheConstant;
import com.xian.im.common.enums.ConsumerQueueEnum;
import com.xian.im.common.event.system.EventBusListener;
import com.xian.im.common.event.user.model.UserEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Component;

/**
 * @program: xian-im-server
 * @description: 用户事件
 * @author: liru.xian
 * @create: 2021-02-01 16:47
 **/
@Component
public class UserEventListener extends AbsEventListenner implements EventBusListener {

    @Autowired
    private CacheManager cacheManager;

    @Subscribe
    public void  doHandler(UserEvent event){
        // Redis与MySQL双写一致性保证
        cacheManager.getCache(EhcacheConstant.USER).clear();
        createEvent(event);
        cacheManager.getCache(EhcacheConstant.USER).clear();
    }

    @Override
    ConsumerQueueEnum queueEvent() {
        return ConsumerQueueEnum.USER_EVENT;
    }
}
